<?php

/**
 * MVM_MALL 网上商店系统  分类显示
 * ============================================================================
 * 版权所有 (C) 2007-2010 www.mvmmall.com，并保留所有权利。
 * 网站地址: http://www.mvmmall.com
 * ----------------------------------------------------------------------------
 * 这是一个免费开源的软件；这意味着您可以在不用于商业目的的前提下对程序代码
 * 进行修改、使用和再发布。
 * ============================================================================
 * $Author:  www.mvmmall.com  $
 * $Date: 2008-06-28 $
 * $Id: category.php  www.mvmmall.com$
 * ---------------------------------------------
*/

require_once './include/common.inc.php';
require_once MVMMALL_ROOT.'./header.php';
require_once MVMMALL_ROOT.'./include/pager.class.php';
require_once MVMMALL_ROOT.'./include/category_tree.class.php';
$tree           = new tree();
$tree->arr_tree = $cache->get_cache('tree');
$tpl            = false;
$search_sql     = false;
$order_by       = false;
$arr_in         = false;
$page           = $page ? (int)$page : 1;
$action         = (int)$action;
$cat_list       = $db->get_one("SELECT * FROM `{$tablepre}category` WHERE uid = '$action'");
!$cat_list['uid'] && show_msg('ctegory_error');
//判断权限
if($m_check_rank < $cat_list['category_grant']) {
	if(!$m_check_id) {
		show_msg('mvm_grant',GetBaseUrl('logging','login'));
	} else {
		show_msg('grant_member');
	}
}
//多重分类
$rt_cat    = false;
$result    = $db->query("SELECT * FROM {$tablepre}goods_cat WHERE cat_id='$cat_list[uid]'");
while ($rt = $db->fetch_array($result)) {
	$rt_cat[$rt['goods_id']] = $rt['goods_id'];
}
$goods_cat   = $rt_cat ? 'OR uid IN('.implode(",", $rt_cat).')': false;
//end
$arr = implode(',',$tree->get_id($action));
$cat_in = $arr ? $action.','.$arr: $action; 
$search_sql  = "WHERE upv = '1' AND up_date<='$m_now_time' AND goods_category IN($cat_in) $goods_cat";

//排序处理
!$ps_ac &&  $ps_ac = "DESC";
$show_sort = $ps_ac == 'DESC' ? ' ↓ ' : ' ↑ '; 
    switch ($ps_or){
        case 'price': {  $order_by = " ORDER BY goods_sale_price $ps_ac "; $lang['buy_price'] = "<span class=\"show_sort\" >$lang[buy_price] $show_sort</span>"; break; }
        case 'stock': {  $order_by = " ORDER BY goods_stock $ps_ac ";  $lang['stock'] = "<span class=\"show_sort\" >$lang[stock] $show_sort</span>"; break; }
        case 'date':  {  $order_by = " ORDER BY register_date $ps_ac ";  $lang['regdate'] = "<span class=\"show_sort\" >$lang[regdate] $show_sort</span>"; break; }
        default:      {  $order_by = " ORDER BY goods_rank ASC ";}
    }
$ps_ac =  $ps_ac == 'DESC' ? 'ASC' : 'DESC'; 
$price_url = "category.php?action=$action&ps_or=price&ps_ac=$ps_ac&temp=$temp&page=$page";
$stock_url = "category.php?action=$action&ps_or=stock&ps_ac=$ps_ac&temp=$temp&page=$page";
$date_url  = "category.php?action=$action&ps_or=date&ps_ac=$ps_ac&temp=$temp&page=$page";

//显示模式
switch ($temp)
{
	case 'text':{ $tpl='category_text'; break; }
	case 'grid':{ $tpl='category_grid'; break; }
	case 'list':{ $tpl='category_list'; break;}
	default:    { $tpl = $cat_list['category_skin'];}
}
$show_text = "category.php?action=$action&temp=text&page=$page";
$show_grid = "category.php?action=$action&temp=grid&page=$page";
$show_list = "category.php?action=$action&temp=list&page=$page";

$total_count = $db->counter("{$tablepre}goods_table",$search_sql);
$list_num    = $mm_limit_list;//后台可控制显示数量
$rowset      = new Pager($total_count,$list_num,$page);
$from_record = $rowset->_offset();
$result      = $db->query("SELECT uid,price_sale,goods_category,goods_type,goods_advance,goods_name,goods_file1,goods_hit,register_date,goods_market_price,goods_sale_price,goods_stock,goods_brand FROM `{$tablepre}goods_table` $search_sql $order_by LIMIT $from_record, $list_num");
while($list  = $db->fetch_array($result)) {
    $goods[] = goods_array($list);
}
//从系统函数中读取分类
$tree_text   = tree_category($action,$cat_list['category_id']);
//分类HTML 是否 使用 
if(!$cat_list['use_html']) {
     $category_head = dhtmlchars($cat_list['category_head']);
     $category_foot = dhtmlchars($cat_list['category_foot']);
} else { 
     $category_head = $cat_list['category_head'];
     $category_foot = $cat_list['category_foot'];
}
if($rewrite==1){
    $baseurl   = str_replace('1.html','',GetBaseUrl('category',$action));
    $exc       ='.html';
}else {
    $baseurl   = GetBaseUrl('category',$action)."&temp=$temp&page=";
}
$page_list     = $rowset->link($baseurl, $exc);
$mm_mall_title =  $cat_list['category_name']; //标题
$cat_list['category_key']  && $mm_keywords     = $cat_list['category_key']; //关键字
$cat_list['category_desc'] && $mm_description  = $cat_list['category_desc']; //描述
$arr            = $tree->get_parent($action);
$navigation     = urlcat($arr).$cat_list['category_name'];//导航
require_once template($tpl);
footer();
